Skip to content

Ctf3d ci - #2

Closed
bHimes wants to merge 151 commits into
mainfrom
ctf3d_ci
Closed

Ctf3d ci#2
bHimes wants to merge 151 commits into
mainfrom
ctf3d_ci

Conversation

@bHimes

@bHimes bHimes commented Mar 11, 2026

Copy link
Copy Markdown

Let's put claude review through the ringer, this contains a lot of work.

…align classes to each other and related functionality that is years long broken
…encies that make editing code hard. The formater did some things I don't like, and will rever like alignment of function input/outputs.
…omos and also error handling when no subTomos are available.
…the abs value is taken to be compatible with existing projects. This can be removed at some point in the future or with a allow over focus option
bHimes and others added 19 commits September 22, 2025 07:50
…ry logic

- Add atomic save operation using temporary files and atomic rename
- Implement comprehensive MAT file integrity checking to detect HDF5 corruption
- Add retry logic (N=2) with integrity validation before final save
- Force filesystem sync after writes to ensure data persistence
- Detect and handle specific HDF5/deflate compression corruption errors
- Maintain existing backup functionality
- Add detailed error reporting and warnings for failed attempts

This addresses frequent MAT file corruption issues by:
1. Using atomic operations to prevent partial writes
2. Validating file integrity before committing changes
3. Retrying failed saves to handle transient I/O issues
4. Preserving data through comprehensive backup strategies

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add detailed error messages to integrity check function
- Fix silent failure case where save loop could exit without success
- Return specific error reasons (file missing, empty, corrupt, etc.)
- Add final success check with explicit error if all attempts fail
- Improve warning messages with specific failure reasons

This should help diagnose why MAT files aren't being written after averaging.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…utility

Addresses critical HDF5/MAT file corruption issues during copy operations by:

**Enhanced Atomic Save Operations:**
- Add post-move integrity verification to catch filesystem corruption
- Implement additional sync and pause before move operations
- Add move operation success checking with detailed error reporting
- Handle rare post-move corruption scenarios with file cleanup

**New Safe Copy Utility (BH_safeCopyMatFile):**
- Multi-strategy copying: load-and-save, filesystem copy, rsync with checksum
- Comprehensive integrity verification at each step
- Automatic fallback between methods if one fails
- Handles HDF5 sparse file corruption issues with Unix cp command
- Creates backups before overwriting existing files

**Technical Solutions for Known Issues:**
- Addresses HDF5 sparse file corruption during cp operations
- Implements filesystem cache flushing and sync barriers
- Uses atomic rename operations instead of copy when possible
- Provides rsync with checksum verification for Unix systems

This resolves the specific issue where MAT files become corrupt after
copying with Unix cp command, even when the original file loads correctly.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added extensive debug output to track every step of the save operation:

**Save Operation Debugging:**
- Input data validation (class, field count, currentCycle)
- Disk space information before save attempts
- Detailed timing for each operation (save, sync, integrity check, move)
- Temp file creation and size verification
- Move operation success/failure with detailed error messages
- Exception catching with full stack traces and identifiers

**Integrity Check Debugging:**
- File existence and size validation
- Variable information extraction with timing
- Variable name listing and subTomoMeta detection
- Variable metadata (size, class, bytes)
- Structure loading with timing
- Field enumeration and key field verification
- Detailed error classification (HDF5/compression vs general)

This should provide complete visibility into exactly where and why
the atomic save operations are failing during averaging.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ecture

This commit resolves the critical "MATLAB:load:numColumnsNotSame" corruption
issue by fundamentally changing how metadata is passed between BH_average3d
and BH_fscGold_class.

Key changes:
- Refactor BH_fscGold_class to accept parameters directly instead of loading
  full metadata from disk, eliminating problematic disk I/O operations
- Update BH_average3d to pass minimal data to fscGold and update in-memory
  subTomoMeta directly, removing the corruption-prone reload operation
- Remove masterTM struct entirely from fscGold, working directly with
  passed parameters and returning only modifications
- Clean up debug print statements from both functions

This architectural change eliminates the root cause of corruption while
maintaining all scientific functionality. Testing confirmed that the
refactored version completely eliminates the corruption issue.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix worker count calculation to use nCpuCores instead of GPU scaling
- Restore complete process_single_tilt_series function with real processing
- Add debug checks for serial execution enforcement
- Implement collect-then-reassemble parallel pattern
- Fix field names in starfile output (anglePsi vs e1, etc.)
- Add comprehensive debugging with revert tags
- Update EMC_parpool with integrated cleanup
- Enhance EMC_setup_tmp_cache for cisTEM prefix support

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed critical bug where particles were lost during tilt series processing:

**Root Cause:**
- n_included_this_prj was reset per projection, only counting last projection
- Tilt series with particles in early projections but empty final projection
  would discard entire tilt series stack despite particles in memory

**Key Changes:**
- Replace per-projection counter with n_particles_this_tilt_series
- Track particles across ALL projections in each tilt series
- Add comprehensive debug output for validation and troubleshooting
- Remove skip_to_end and multi-node logic (moved to external programs)
- Add error handling for particle stack assignment failures
- Clean up unused variables and verbose output

**Validation Fix:**
- particles_stack_added now equals total_particles_in_stack
- Stack slices match star file records exactly
- Comprehensive debug shows particle flow through entire pipeline

All 35,458 particles now properly saved to both stack and star files.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Removed debug prints that referenced undefined particles_processed_total variable
- Function now runs without undefined variable errors
- Core validation logic preserved and functional

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
… parsing

- Fix file format detection issue where .tmp files were interpreted as ASCII instead of binary MAT files
- Change temp file extension from .tmp to .tmp.mat for proper format recognition
- Prioritize v7 format over v7.3 for better immediate load compatibility
- Add robust retry logic with delays for v7.3 (HDF5) format files
- Implement multiple sync attempts for HDF5 files to ensure data is fully flushed
- Fix mask command to not require parameter file (add to multiGPUs=0 list)
- Fix mask command argument count check (was expecting 5, now correctly expects 4 for shape-based masking)

The main issue was that MATLAB's load() function was misidentifying .tmp files as ASCII text files
instead of binary MAT files, causing "Unknown text on line number 1" errors. Using .tmp.mat extension
ensures proper format detection.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…rojections

- Add Y-shift padding strategy to handle shifts during 3D sampling
- Implement batch processing for slabs to reduce GPU memory usage
- Add emc_estimate_slice_batch_size for dynamic batch sizing
- Add EMC_tlt_get_projection_values helper for TLT column extraction
- Add EMC_syntheticTomogram_starfile variant for starfile input
- Update EMC_setup_synthetic_project with improved file handling

Note: Shift sign convention still needs verification

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Switch from TILT (Y-axis only) to SPIDER (ZYZ) rotation convention
- Add Y-padding calculation to account for in-plane rotation during chunking
- Update coordinate transformations to use full 3x3 rotation matrix
- Store 2D rotation matrix (A11, A12, A21, A22) in TLT columns 7-10
- Update EMC_setup_synthetic_project to read rotation matrix from TLT for .xf file
- Add clarifying comments to BH_defineMatrix about rotation conventions

The rotation matrix stored is the inverse of the applied rotation, following
IMOD convention where .xf describes how to align raw projections.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add wrapper interface for simulation functions:
- emClarity simulate tomogram    - Generate synthetic 3D tomogram
- emClarity simulate tlt_file    - Generate synthetic tilt geometry file
- emClarity simulate projections - Generate tilt series from tomogram
- emClarity simulate project     - Set up complete emClarity project

Template input supports single MRC or text file with MRC/PDB pairs
(alternating lines: odd=MRC, even=PDB/CIF).

KNOWN ISSUE: There are inconsistencies in the transformed output
suggesting a misalignment with IMOD conventions. The coordinate
transforms and rotation matrices may not match IMOD's expected
handedness or origin conventions.

TODO: Add debug mode for precise coordinate validation:
- Generate tomogram with well-defined cross-hair densities at known
  positions for sub-pixel precision coordinate verification
- Option to skip Poisson noise draw for cleaner signal
- Option to skip CTF application for simpler debugging
- Compare reconstructed particle positions against ground truth CSV
  to isolate where convention mismatches occur

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Enhance adamOptimizer with per-parameter learning rates, bounds
  clamping, score history, convergence detection, and parameter
  freezing/unfreezing
- Create EMC_refine_tilt_ctf.m: standalone ADAM refinement engine
  with Fourier upsampling peak finder, numerical gradients via
  central finite differences, warmup phase, and convergence detection
- Add Pass 2 refinement scaffolding to BH_to_cisTEM_mapBack.m:
  initial star file saved as _initial.star, _cisTEMOriginalImageFilename
  column added, per-particle metadata stored, tilt-dependent scoring
- Add refinement parameters to BH_parseParameterFile.m:
  tomo_cpr_astigmatism_angle_range, tomo_cpr_upsample_factor,
  tomo_cpr_upsample_window, tomo_cpr_maximum_iterations,
  tomo_cpr_z_offset_bound_factor
- Add unit tests for adamOptimizer and Fourier upsampling
- Add compare_star_files.m plotting script for diagnostics

Pass 2 currently uses placeholder reference tiles; reference
projection integration is the next step.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Create ctf/EMC_ctf_refine_from_star.m: standalone program that accepts
  a star file, particle stack, and external 3D reference volume (e.g. from
  cisTEM reconstruction) to refine per-tilt defocus/astigmatism and
  per-particle Z offsets using ADAM optimization. Includes Euler angle
  convention debug block that tests 4 permutations and exits early for
  user validation.

- Simplify BH_to_cisTEM_mapBack.m: remove Pass 2 refinement block (now
  handled by the standalone program), add tilt angle as column 30 in star
  file (_cisTEMOriginalXPosition), add optional tile size override via
  cisTEM_output_tile_size parameter.

- Register 'ctf ctfRefine' subcommand in testScripts/emClarity.m

- Add cisTEM_output_tile_size parameter to BH_parseParameterFile.m

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… license is expired, working on that but for now, let's test out the new claude code review.
@bHimes bHimes closed this Mar 11, 2026
@bHimes bHimes reopened this Mar 11, 2026
@bHimes bHimes closed this Mar 11, 2026
@bHimes bHimes reopened this Mar 11, 2026
@bHimes bHimes closed this Mar 11, 2026
bHimes added a commit that referenced this pull request Mar 16, 2026
ActionsPage.tsx:
- aria-live tooltip now changes text content (empty→message) on demoBlocked
  toggle so screen readers actually announce the notification (Round 9 #1)
- Change `projectId != null` to strict `!== null` for consistency (Round 9 StochasticAnalytics#6)

JobsPage.tsx:
- Add `effectiveIsLoading = isLoading && !isDemo` to mask stale loading state
  synchronously when navigating real→demo, eliminating one-frame spinner flash
  (Round 9 #2); replace all isLoading references in JSX with effectiveIsLoading
- Replace IIFE-in-JSX render pattern with direct conditional (Round 9 StochasticAnalytics#4)
- Add Home/End keyboard navigation to JobTable grid per WAI-ARIA 1.2 §3.14
  (Round 9 #3)
- Remove redundant `isDemo` from auto-refresh useEffect dep array; fetchJobs
  already captures isDemo via its own useCallback deps (Round 9 StochasticAnalytics#5)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bHimes added a commit that referenced this pull request Mar 16, 2026
Defect #1 (MEDIUM): entry_base symlink inconsistency
- Changed `entry_base = display_path` to `entry_base = real_path_str` in
  browse_filesystem().  When the browse target is itself a symlink, display_path
  holds the pre-realpath (symlink) path while response.path is the fully-resolved
  real path.  Using display_path as the entry prefix violated the documented
  contract that entry.path == response.path + "/" + entry.name.

Defect #2 (MEDIUM/LOW): two tests left entry-path contract unchecked
- Added backend/tests/test_filesystem_entry_path_contract.py with four new
  regression tests that explicitly assert entry["path"] values.  Covers the
  symlink-target scenario (test_symlink_target_entry_paths_use_real_path) and
  the single-subdir scenario (test_only_directories_entry_path_matches_parent),
  plus a generic contract test and a root-path test.  Existing test files were
  not modified.

Defect #3 (MEDIUM): _PATH_MAX guard was strict greater-than (> 4096)
- Changed `> _PATH_MAX` to `>= _PATH_MAX` in _validate_browse_path().
  PATH_MAX (4096) includes the NUL terminator, so the maximum valid path is
  4095 bytes.  Paths of exactly 4096 bytes previously bypassed the 400 guard
  and reached the OS where they triggered ENAMETOOLONG, surfacing as 404.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bHimes added a commit that referenced this pull request Mar 17, 2026
- Remove parseSSHUserHost host:/user: label rendering (binding decision #2);
  SSH profiles now show raw commandTemplate as sole display string
- Add useRef + cleanup to all four setTimeout handlers to prevent
  timer stacking and memory leaks on unmount
- Fix text-gray-400 → text-gray-500 dark:text-gray-400 on four
  informational strings to achieve WCAG AA contrast (≥4.5:1)
- Remove stale comment in RunProfileValidationSection that referenced
  removed profile-sync behavior

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bHimes added a commit that referenced this pull request Mar 17, 2026
- Remove message-text regex from TypeError guard (Binding Decision #2 violation):
  fetch() only throws TypeError for network failures, so the /fetch|network|load failed/i
  test was both fragile and unnecessary.
- Split combined focus-save + navigate useEffect into two separate effects so that
  a dynamic initialPath change no longer triggers spurious focus restoration mid-session.
- Add aria-current="page" to terminal breadcrumb segment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bHimes added a commit that referenced this pull request Mar 21, 2026
- Fix dropdown clipping: use fixed positioning with z-[9999] to escape
  overflow-hidden ancestors (defect #1)
- Fix ARIA contract: replace role="listbox"/role="option" on buttons with
  role="menu"/role="menuitem" on divs, add arrow-key navigation (defect #2)
- Return focus to trigger button on dropdown close via Escape, click-outside,
  or item selection (defect #3)
- Use per-item error state instead of shared error that hides the entire
  snapshot list after a single load failure (defect StochasticAnalytics#4)
- Guard against race condition: ignore clicks while a snapshot is already
  loading (defect StochasticAnalytics#5)
- Add aria-live="polite" to export result message for screen readers (defect StochasticAnalytics#6)
- Add aria-live and role="status"/"alert" to loading/error states inside
  dropdown for screen reader announcements (defect StochasticAnalytics#7)
- Add confirmation feedback message after snapshot successfully loaded into
  form (defect StochasticAnalytics#8)
- Add logging for malformed snapshot files skipped by list_snapshots instead
  of silent drop (defect StochasticAnalytics#9)
- Add ambiguous-match guard to load_snapshot matching export_snapshot_m
  pattern, with 409 HTTP response (defect StochasticAnalytics#10)
- Document that ExportMButton.handleExport creates a permanent snapshot as
  side-effect of the export flow (defect StochasticAnalytics#11)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
bHimes added a commit that referenced this pull request Mar 21, 2026
- Defect #1: Use ReactDOM.createPortal for dropdown menu to prevent
  scroll/resize drift from position:fixed workaround. Added scroll/resize
  event listeners to update portal position dynamically.
- Defect #2: Render loadedMessage success span via portal to escape
  overflow-hidden ancestors and remain visible to sighted users.
- Defect #3: Move focus to first menu item when dropdown opens and
  snapshots are loaded, enabling keyboard users to reach menu items.
- Defect StochasticAnalytics#4: Remove aria-live="polite" from role="menu" element to
  prevent duplicate/flood announcements. Loading status uses its own
  aria-live region inside the menu instead.
- Defect StochasticAnalytics#5: Change HTTP 409 to 422 for ambiguous snapshot ID prefix
  in both export-m and get_snapshot endpoints.
- Defect StochasticAnalytics#6: Handle json.JSONDecodeError and KeyError in load_snapshot
  by raising ValueError with descriptive message instead of leaking
  raw exception text in 500 response.
- Defect StochasticAnalytics#7: Remove mt-1 class from portal-rendered dropdown (inline
  style provides the 4px gap directly via top offset calculation).
- Defect StochasticAnalytics#8: ExportMButton uses role="alert" with aria-live="assertive"
  for error messages so failures are announced to screen readers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant